package root.electronclass.electronclass.other

import android.app.Activity
import android.content.Intent
import android.view.View
import androidx.core.os.bundleOf
import androidx.core.view.isVisible
import root.electronclass.electronclass.common.base.ViewBindingActivity
import root.electronclass.electronclass.MainActivity
import root.electronclass.electronclass.databinding.ActivityAttestationBinding
import root.electronclass.electronclass.setup
import root.electronclass.electronclass.mvp.GlobalParameter

/**
 * 通用认证
 */
class AttestationActivity : ViewBindingActivity<ActivityAttestationBinding>() {
    private var isStudent = false
    override fun init() {
        binding.top.setup(lifecycle, "")
        click()

        if (GlobalParameter.getEcardInfo().type == 5){
            binding.faceCl.visibility = View.INVISIBLE
        }
        ///如果是学生考勤，就不显示人脸
         isStudent = intent.getBooleanExtra("isStudent",false)
        if (isStudent){
            binding.scanCl.visibility = View.INVISIBLE
        }
    }

    private fun click() {
        /**
         * 刷卡
         */
        binding.cardCl.setOnClickListener {
            val i = Intent(this@AttestationActivity,CardActivity::class.java)
            i.putExtra("RequestCode",intent.getIntExtra("RequestCode",0))
            startActivityForResult(i,0)
        }
        /**
         * 扫码
         */
        binding.scanCl.setOnClickListener {
            val i = Intent(this@AttestationActivity,ScanActivity::class.java)
            i.putExtra("RequestCode",intent.getIntExtra("RequestCode",0))
            startActivityForResult(i,0)
        }
        /**
         * 人脸
         */
        binding.faceCl.setOnClickListener {
            val i = Intent(this@AttestationActivity,FaceActivity::class.java)
            i.putExtra("RequestCode",intent.getIntExtra("RequestCode",0))
            startActivityForResult(i,0)
        }

        binding.back.back.setOnClickListener{
            val intent = Intent(this@AttestationActivity,MainActivity::class.java)
            intent.putExtra("SUCCESS",false)
            setResult(Activity.RESULT_OK,intent)
            finish()
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if(resultCode == Activity.RESULT_OK && !isStudent){
            val intent = Intent(this@AttestationActivity,MainActivity::class.java)
            intent.putExtra("SUCCESS",true)
            intent.putExtras(getIntent().extras?: bundleOf())
            setResult(Activity.RESULT_OK,intent)
            finish()
        }
    }

    companion object{




        @JvmStatic
        val personal = 10001

        @JvmStatic
        val HOMEWORK = 11000//家庭作业

        @JvmStatic
        val CURRICULUM = 11001//课程签到

        @JvmStatic
        val MANAGER_ROTA = 11002//管理值日

        @JvmStatic
        val ATTENDANCE = 10002//考勤

        @JvmStatic
        val STUDYDOWN = 10003//下载


        @JvmStatic
        val APPLICATION = 10004//应用中心


        @JvmStatic
        val ideaBox_requestCode = 10005

        @JvmStatic
        val ATTESTATION = 10006 //身份认证
    }
}